Read me

CompileTeX for BBEdit

CompileTeX is an AppleScript/Shell script combination for use with
BBEdit. It allows you to duplicate some TeXShop functionality in BBEdit
(in particular the use of master documents through the %SourceDoc
comment or the newer #!TEX Root=file.tex syntax). It also allows you to
generate draft documents without touching the master document (by
passing \PassOptionsToClass{draft}{your main documentclass} to pdflatex
before starting the TeX run).

You may need to adapt the script to your needs. In particular I include
scripts to generate metapost graphics (and I assume that the figures
reside in a folder "Figures" next to the master document). I use a
separate script to translate the metapost figure into pdf if needed. Of
course if you do not use metapost, the figure scripts are useless, since
you aren't likely to edit your figures in a text editor anyway.

This version is dedicated to BBEdit 8 and TextWrangler. The new window
handling applescript commands broke the old version (and the new syntax
will not work on BBEdit 7). The old version is no longer available. Note
that the TextWrangler scripts are a trivial modification of the BBEdit
scripts (the application name in the "tell" blocks had to be altered.

BBedit is commercial software, but TextWrangler is provided at zero
cost, and for your convenience a copy of TextWrangler is included on the
disk with kind permission from the folks at BareBones software. Links to
the product pages of both applications are included in this folder.

The script-set has two main parts: a shell script that runs in the
Terminal that does the actual processing. The AppleScripts merely call
this shell-script with the correct parameters. I've taken this approach,
because I really dislike the AppleScript syntax: I find it unclear, and
I never seem to be able to find the correct syntax first time round.

A list of descriptions is added at the end of this document.

Maarten

*** HOW TO INSTALL ***

1 - Copy the folder "ShellScripts" in this directory to your "Library"
    folder in your home folder.
2 - Double-click the file "BBEdit-TeX-AppleScripts.dmg".
3 - From the disk image you just mounted, you should copy the folder
    "01)TeX Compilation" to the folder "Scripts" in the folder "BBEdit"
    in the folder "Application Support" in your "Library" folder. Eh?
    Exactly, in traditional unix notation, that becomes
    '~/Library/Application Support/BBEdit/Scripts/'. If you have run
    BBEdit once, this folder should have been created already. (It is a
    good idea to run TextWrangler before installing these scripts).
4 - [optional] You can alter the name of a script to move the item up or
    down in the menu: the number in front of the ")" will determine the
    sort order within the menu. The same is true for for the levels
    below. You may also want to set some shortcuts: From the "Windows"
    menu, go to the "Palettes" sub-menu and select "Scripts from there.
    You can now select a script, and set a key for it. The BBEdit and
    TextWrangler help both contain a lot of extra information to help
    you here.

Note: The AppleScripts are on a disk image because they rely on resource
      forks. These resource forks are likely to disappear when stored 
      directly on a CD.

Note: The scripts are rather sensitive to the names of files and
      directories: all directories in which files must be processed by
      these scripts may not contain spaces, or special characters.

*** Disclaimer ***

This software is in the public domain, entirely unsupported. It does
what I need it to do, and is distributed in the hope that it might be
useful to others. There is no warranty of any kind.

I disclaim all copyrights on these scripts.

*** list of the supplied scripts with short descriptions ***

Most scripts will save all files currently open in BBEdit or
TextWrangler, unless they haven't been saved yet, unless you are calling
the script on an unsaved active document. Yes, I do like Monty Python.

Run pdflatex.scpt   - Typeset the master document once.
Run BibTeX.scpt     - Run bibtex on the master of the front document.
Run MakeIndex.scpt  - Run makeindex on the front document. It assumes
                      that a file with the same name as the master
                      document, but with an .ist extension exists to
                      stand in as an index style file.
Show result.scpt    - Open the typeset result of the front file
                      (metapost or (la)tex in your preferred pdf-viewer).
                      The viewer to use is set near the top of the shell
                      script.
Synchronise with TeXniscope.scpt - If you use pdfsync, you can use this 
                      to go to the point in the typeset document which
                      corresponds to the insertion point.
Make draft version.scpt - Pass the draft class option to the
                      documentclass, allowing TeX to mark overful lines.
                      Note that if used this way, the draft option does
                      not reach any included packages (like graphics or
                      hyperref). Figures are included in the normal way.
Make fast draft version.scpt - Pass the draft class option to the
                      documentclass, allowing TeX to mark overful lines.
                      In addition, the draft option is passed to
                      hyperref and graphics as well, so figures are not
                      included, and hyperlinks are not created. This
                      speeds up pdflatex.
Full document compilation.scpt - The whole shebang: pdflatex, bibtex,
                      pdflatex & pdflatex (for as long as there happen
                      to be undefined references etc). Including
                      makeindex in this cycle is left as an exercise to
                      the reader...
Show figure mps.scpt - Run the front document through metapost, and open
                      the result in the preferred pdf viewer (a
                      temporary pdf version is created for viewing).
                      This requires the front most file to contain
                      metapost source, with a single figure (number 0).
Show figure pdf.scpt - Very similar to the previous script, except that
                      here the pdf version will be kept (and the mps
                      version will be ditched).
Make all figures mps.scpt - This will run all .mp files in the figures
                      directory next to the master document through
                      metapost, and create the figures. Only generate
                      .mps output
Make all figures pdf.scpt - Same as above, create pdf files.
Select previous marker.scpt - The string "<##>" (without the quotes) is 
                      a marker, and this script will jump to the
                      previous one. Practical for templates and glossary
                      items (The latter for BBEdit only).
Select next marker.scpt - same as above, except for the direction.
Open master file.scpt - Search the front document for a master
                      directive, and open the referenced file.
Open selected file.scpt - Search the current line for \input, \include
                      and \includegraphics commands and open the
                      document you find here. The \includegraphics
                      command is assumed to reference a metapost figure,
                      and will open the .mp associated file (or at least
                      try to).
Open all referenced files.scpt - Same as above, except the complete
                      document is searched for referenced files - and
                      they are all opened.
Open log file.scpt  - Open the log file of the master document to check
                      for errors.

Encrypt PDF.scpt    - This requires pdftk to be installed, see: 
                      http://www.pdfhacks.com/pdftk/
Run xetex.scpt, Run xelatex.scpt, Run latex.scpt, Run pdftex.scpt, Run
tex.scpt            - The scripts in the "Other TeX Engines" all run the current
                      master document once through the respective
                      engine. Other scripts/TeX engines can be added
                      easily: as long as the command ends in "tex", you
                      can just feed the command to the script. So if you
                      have a command "froobletex", the switch
                      -froobletex is acceptable, and there is no need to
                      actually change the shell script.
Run Make.scpt       - Run make pdf in the directory where the master
                      document lives. Other targets are added easily,
                      should the need arise.
Run pdflatex+PP4.scpt - Run pdflatex, followed by a run of pp4, for
                      producing presentations.
